import Taro from "@tarojs/taro";
import {InnerAudioContextManger} from "./InnerAudioContextManger";

let baseUrl = process.env.TARO_APP_SERVER_API!!;
const scanSuccessVoice = `${baseUrl}voices/scanSuccess.mp3`
const barcodeNotExistedVoice = `${baseUrl}voices/barcodeNotExisted.mp3`
const barcodeRepeatVoice = `${baseUrl}voices/barcodeRepeat.mp3`
let innerAudioContextManger = new InnerAudioContextManger(true);

export async function scanSuccess(){
    await Taro.vibrateShort()
    await Taro.showToast({
        title: `扫描成功`,
        icon:"success",
    })
    innerAudioContextManger.play(scanSuccessVoice)
}

export async function barcodeNotExisted(barcode:string){
    Taro.vibrateLong()
    await Taro.showToast({
        title: `不存在此条码\r\n${barcode}`,
        icon:"error"
    })
    innerAudioContextManger.play(barcodeNotExistedVoice)
}

export async function barcodeRepeated(message:string="条码已存在"){
    await Taro.vibrateLong()
    await Taro.showToast({
        title: message,
        icon:"error",
    })
    innerAudioContextManger.play(barcodeRepeatVoice)
}